const { pickExclude } = require("../../vant-ui/dist/common/utils");

Page({
    data: {
        music:""
    },
    
    onConfirm(event){
        var value = event.detail.value;
        var that=this;
        // console.log(value);
        var music=[];

        var url=`http://47.108.197.28:3000/search?keywords=${value}`
        wx.request({
            url,
            data: {},
            method: 'GET', 
            header: {}, 
            success: function(res){
               var song=res.data.result.songs;
            //    var pic=[];
            
               song.forEach(item=>{
                   console.log(item);
                   var {id,name,artists}=item;
                   
                    wx.request({
                        url: `http://47.108.197.28:3000/song/detail?ids=${id}`,
                        data: {},
                        method: 'GET', 
                        header: {}, 
                        success: function(list){
                            // console.log(list);
                            var {al}=list.data.songs[0];
                            // console.log(al.picUrl)
                            // var music = that.data.music;
                            var pic=al.picUrl
                            music.push({id,name,pic,artists:artists[0].name})
                            console.log(music)
                            that.setData({music})
                        }
                        
                    })
                    
                    
               })
                
               
            }
        })
    }
})